function openCbox() {
    var cbox = document.getElementById("conversions-box");
    cbox.setAttribute("class", "conversions-box-open");
    document.getElementById('conversions-box-close').onclick = function() {
        closeCbox();
        return false
    }
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y)
        }
    }
}

function closeCbox() {
    var cbox = document.getElementById("conversions-box");
    cbox.setAttribute("class", "");
    var c_name = "conversionbox_closed";
    var value = true;
    var exdays = 30;
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value + ";path=/;domain=." + document.location.hostname
}
var ConversionsBox = function(t, u, h) {
    if (!getCookie("conversionbox_closed")) {
        var cbox = document.createElement("div");
        cbox.setAttribute("id", "conversions-box");
        var prefix1 = 'http://';
        var prefix2 = 'https://';
        if (u.substr(0, prefix1.length) !== prefix1 && u.substr(0, prefix2.length) !== prefix2) {
            u = prefix1 + u
        }
        document.getElementsByTagName("body")[0].appendChild(cbox);
        document.getElementById('conversions-box').innerHTML = '<div class="inner"><a href="#" id="conversions-box-close">(i already like it)</a><span>' + decodeURIComponent(t) + '</span><iframe src="//www.facebook.com/plugins/like.php?href=' + encodeURIComponent(u) + '&amp;send=false&amp;layout=button_count&amp;width=95&amp;show_faces=false&amp;font&amp;colorscheme=light&amp;action=like&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:95px; height:21px;" allowTransparency="true"></iframe></div>';
        var vscroll;
        var windowHeight = Math.max(Math.max(document.body.scrollHeight, document.documentElement.scrollHeight), Math.max(document.body.offsetHeight, document.documentElement.offsetHeight), Math.max(document.body.clientHeight, document.documentElement.clientHeight));
        var w = window,
            d = document,
            e = d.documentElement,
            g = d.getElementsByTagName('body')[0],
            x = w.innerWidth || e.clientWidth || g.clientWidth,
            y = w.innerHeight || e.clientHeight || g.clientHeight;
        var dont_check_scroll = false;
        if (y == windowHeight) {
            setTimeout('openCbox();', 3000);
            dont_check_scroll = true
        }
        var showOn = windowHeight / 60 * 10;
        if (dont_check_scroll == false) {
            window.onscroll = function(s) {
                var top = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
                vscroll = (document.all ? top : window.pageYOffset);
                if (vscroll >= showOn) {
                    openCbox();
                    window.onscroll = false
                }
                if (y + vscroll >= windowHeight) {
                    openCbox();
                    window.onscroll = false
                }
            }
        }
    }
}
